package com.ry;

import com.ry.util.timepick.R;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {
	private TabHost tab;
	private RadioGroup rg;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		init();
	}

	private void init() {
		tab = getTabHost();

		int count = ConValue.mTabClassArray.length;
		for (int i = 0; i < count; i++) {
			TabSpec tabSpec = tab.newTabSpec(ConValue.mTextviewArray[i]).setIndicator(ConValue.mTextviewArray[i])
					.setContent(getTabItemIntent(i));
			tab.addTab(tabSpec);
		}

		rg = (RadioGroup) findViewById(R.main.rg);
		rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
				case R.main.priceBtn:
					MainActivity.this.getLocalActivityManager().getCurrentActivity();
					tab.setCurrentTabByTag(ConValue.mTextviewArray[0]);
					break;
				case R.main.orderBtn:
					MainActivity.this.getLocalActivityManager().getCurrentActivity();
					tab.setCurrentTabByTag(ConValue.mTextviewArray[1]);
					break;
				case R.main.startBtn:
					MainActivity.this.getLocalActivityManager().getCurrentActivity();
					tab.setCurrentTabByTag(ConValue.mTextviewArray[2]);
					break;
				case R.main.myBtn:
					MainActivity.this.getLocalActivityManager().getCurrentActivity();
					tab.setCurrentTabByTag(ConValue.mTextviewArray[3]);
					break;
				}
			}

		});

		((RadioButton) rg.getChildAt(2)).toggle();
	}

	private Intent getTabItemIntent(int index) {
		Intent intent = new Intent(this, ConValue.mTabClassArray[index]);
		return intent;
	}

	public static final class ConValue {
		public static String mTextviewArray[] = { "价格", "订单", "开始", "我的" };

		public static Class<?> mTabClassArray[] = { PriceActivity.class, OrderActivity.class, StartActivity.class,
				MyActivity.class};

	}

}
